package com.supermarket.spark.util

import java.util.Properties
import org.apache.spark.sql.DataFrame
import org.apache.spark.sql.SparkSession

object JdbcUtil {
  val jdbcUrl = "jdbc:mysql://localhost:3306/supermarket?useSSL=false&serverTimezone=UTC"

  val connectionProperties = new Properties()
  connectionProperties.put("user", "root")
  connectionProperties.put("password", "your_password")
  connectionProperties.put("driver", "com.mysql.cj.jdbc.Driver")

  def writeDataFrameToMySQL(df: DataFrame, table: String): Unit = {
    df.write
      .mode("overwrite")
      .jdbc(jdbcUrl, table, connectionProperties)
  }
}